import jwt from 'jsonwebtoken'
const LOCAL_JWT_KEY = "@*BN&VR23"
const LOCAL_REFRESH_JWT_KEY = "*@B#&VB*B"

export const setToken = (token) =>{
    setAccessToken(token.access_token)
    setRefreshToken(token.refresh_token)
}

const setAccessToken = (token) =>{
    localStorage.setItem(LOCAL_JWT_KEY,token)
}

const setRefreshToken = (token) =>{
    localStorage.setItem(LOCAL_REFRESH_JWT_KEY,token)
}

export const getAccessToken = () =>{
    return localStorage.getItem(LOCAL_JWT_KEY);
}

export const getRefreshToken = () =>{
    localStorage.getItem(LOCAL_REFRESH_JWT_KEY);
    return localStorage.getItem(LOCAL_REFRESH_JWT_KEY);
}

export const invalidToken = () =>{
    setAccessToken("")
    setRefreshToken("")
}

export const getUsername = () =>{
    const token = localStorage.getItem(LOCAL_JWT_KEY);
    let data = jwt.decode(token);
    return data.name;
}